package com.heatingcharge.controller.base;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.entity.base.NetContract;
import com.heatingcharge.param.NetContractParam;
import com.heatingcharge.service.base.INetContractService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-12-27
 */
@RestController
@RequestMapping("/net-contract")
public class NetContractController {
    @Autowired
    INetContractService iNetContractService;

    @ApiOperation(value = "分页获取入网合同信息",notes = "分页获取入网合同信息")
    @GetMapping()
    public R getNetContract(Page page, NetContract netContract){
        IPage<NetContract> chargePlanDTOIPage=iNetContractService.getNetContracts(page,netContract);
        return R.ok(chargePlanDTOIPage);
    }

    @ApiOperation(value = "新增入网合同",notes = "新增入网合同")
    @PostMapping
    public R saveNetContract(@RequestBody NetContractParam netContractParam){
        if (iNetContractService.save(netContractParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新入网合同",notes = "更新入网合同")
    @PutMapping
    public R updateNetContract(@RequestBody NetContractParam netContractParam){
        if (iNetContractService.update(netContractParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "入网收费",notes = "入网收费")
    @PutMapping("/charge")
    public R netCharge(@RequestBody NetContractParam netContractParam){
        if (iNetContractService.charge(netContractParam)){
            return R.ok();
        }
        return R.error();
    }
}

